package com.misty.admin.controller.adminController;


import com.misty.admin.service.TypeService;
import com.misty.common.bean.Result;
import com.misty.dao.domain.Type;
import com.misty.dao.mapper.TypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cthulhu
 * @since 2022-11-21
 */
@RestController
@RequestMapping("/type")
@PreAuthorize("hasAuthority('type')")
public class TypeController {

    @Autowired
    private TypeService typeService;
    @Resource
    private TypeMapper typeMapper;

    @PostMapping("save")
    public Result<?> save(@RequestBody Type type) {
        return typeService.saveType(type);
    }

    @PutMapping("update")
    public Result<?> update(@RequestBody Type type) {
        return typeService.updateType(type);
    }

    @DeleteMapping("delete")
    public Result<?> delete(@RequestParam(name = "id") Integer typeId) {
        return typeService.deleteType(typeId);
    }

    @GetMapping
    public Result<?> Page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "") String search
    ) {
        return typeService.Page(pageNum,pageSize,search);
    }
}
